﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Entitas;
using Services;

public class FillSystem : ReactiveSystem<GameEntity>
{
    private Contexts _contexts;
    public FillSystem(Contexts context) : base(context.game)
    {
        _contexts = context;
    }

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
    {
        return context.CreateCollector(GameMatcher.ComponentsItem.Removed());
    }

    protected override bool Filter(GameEntity entity)
    {
        return !entity.isComponentsItem;
    }

    protected override void Execute(List<GameEntity> entities)
    {
     
        var gameBoard = _contexts.game.componentsGameBoardComponents;

        for (int column = 0; column < gameBoard.columns; column++)
        {
            var pos=new customData(column,gameBoard.raws+1);
            var rowMin = GetEmptyItemService.Instance.GetNextEmptyRow(pos);

            for (int row = rowMin; row < gameBoard.raws; row++)
            {
               
                    CreateService.Instance
                    .CreateRandomItem(new customData(column,row));
            }

        }
    }
}
